function isroot(user)
{
	if(user==rootUserName)
		return true;
	else
		return false;
}
function drawGraph(topic)
{
	//alert("Came into function:"+topic);
	var sys = arbor.ParticleSystem();
	sys.parameters({stiffness:900, repulsion:2000, gravity:true, dt:0.015});
	sys.renderer = Renderer("#viewport") ;
	var root = sys.addNode(rootUserName,{alpha:'1',use:'root','color':'blue','level': 0,'shape':'dot','label':rootUserName,'tweets':''});
	var i= 0;

	
	//var gfx = arbor.Graphics(canvas);
	for (i=0;i<=n;i++)
	{	
	
		var splitString = vari[i].name.split(" ");
		vari[i].name = splitString[0];
		if(vari[i].topic==topic)
		{
			if(vari[i].feedback==0)
			{
				alert("skipping "+vari[i].name+" due to feedback");
				continue;
			}
			//alert(vari[i].topic+", "+vari[i].name+", "+vari[i].sentiment);
			
				
			var color = getcolor(vari[i].sentiment);
			 var node = sys.addNode(vari[i].name,{'color':color, use:'first','level': 1,'shape':'dot','label':vari[i].name,'tweets':vari[i].tweet});
			 sys.addEdge(root, node, 0.1);
			 //username = vari[i].name;
		}
		//else
			//alert(vari[i].topic+", "+vari[i].name+", "+vari[i].sentiment);
	}
	
	      // sys.eachEdge(function(edge, p1, p2){
          // gfx.line(p1, p2, {stroke:"#b2b19d", width:2, alpha:1})
        // })

}

function feedbackUpdate(user)
{
	alert("gotcha");
	var i=0;
	for(i=0;i<=n;i++)
	{
		if(vari[i].name==user)
		{	
			alert(user+" in js");
			vari[i].feedback = 0;
			alert(vari[i].name+" has feedback: "+vari[i].feedback);
		}
	}
	
}

function init_layout()
{
	//alert("Came into init");
	document.body.style.backgroundImage='url("")';
	document.body.style.background='#ffffff';
	
	$('.removeMe').remove();
	// arbor=document.createElement('div');
	 //arbor.id="arbor"
	// nav=document.createElement('div');
	// nav.id="nav"
	// nav.innerHTML="<p> <pre>                                           a cool twitter visualization tool</pre></p>";
	// arbor.appendChild(nav);
	 //document.getElementById('mydiv').appendChild(arbor);
	 $('.container').append('  <div id="arbor"><div id="nav"><p> <pre>                      a cool twitter visualization tool</pre></p></div>');

}
function getcolor(sentiment)
{
	if(sentiment=="GOOD")
		color="#a7af00";
	else if(sentiment=="BAD")
		color="#922E00";
	else
		color="orange";
	return color;
}
function test(rootUserName,vari,topiclist,n)
{
	
	//alert("here");
	//alert(n);
	init_layout();
	i=0;
	 while(topiclist[i] != null)
	 {
	  //alert("topic "+i+" = "+topiclist[i]);
	  //$('<a href="#"></a>').text(topiclist[i]).click(drawGraph(topiclist[i]);).appendTo('.layer1');
	  $('.layer1').append('<a href="javascript:drawGraph('+'\''+topiclist[i]+'\');" style="text-decoration:none">'+topiclist[i]+'</a>&nbsp&nbsp&nbsp&nbsp');
	  i++;
	 }
	var topic= vari[0].topic;
	drawGraph(topic);
	//alert("done");
}